package com.umer.pinban.scan.dialog;

import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.common.ui.recycleview.listener.OptListener;
import com.common.utils.screen.ScreenUtil;
import com.lxj.xpopup.animator.PopupAnimator;
import com.lxj.xpopup.core.BottomPopupView;
import com.umer.pinban.R;
import com.umer.pinban.bean.PersonnelList;
import com.umer.pinban.scan.adapter.PersonnelListSelectAdapter;
import org.greenrobot.eventbus.EventBus;
import java.util.List;

/**
 * 选择优美师
 */
public class DialogSelectStaff extends BottomPopupView implements OptListener {

    private EventBus eventBus;
    private Context context;
    private List<PersonnelList> personnelListList;
    private PersonnelListSelectAdapter personnelListSelectAdapter;
    private RecyclerView recyclerView;

    public DialogSelectStaff(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    // 返回自定义弹窗的布局
    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_select_staff;
    }
    // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
    @Override
    protected void onCreate() {
        super.onCreate();
        recyclerView = findViewById(R.id.recyclerView);
        findViewById(R.id.linear_cancle).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss(); // 关闭弹窗
            }
        });
        findViewById(R.id.linear_ok).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss(); // 关闭弹窗
            }
        });

        personnelListSelectAdapter = new PersonnelListSelectAdapter(context,personnelListList,
                R.layout.item_dialog_one,this);
        recyclerView.setLayoutManager(new GridLayoutManager(context, 9));
        recyclerView.setAdapter(personnelListSelectAdapter);

    }
    // 设置最大宽度，看需要而定
    @Override
    protected int getMaxWidth() {
        return ScreenUtil.getInstance().getScreenWidth();
    }
    // 设置最大高度，看需要而定
    @Override
    protected int getMaxHeight() {
        return super.getMaxHeight();
    }
    // 设置自定义动画器，看需要而定
    @Override
    protected PopupAnimator getPopupAnimator() {
        return super.getPopupAnimator();
    }
    /**
     * 弹窗的宽度，用来动态设定当前弹窗的宽度，受getMaxWidth()限制
     *
     * @return
     */
    protected int getPopupWidth() {
        return ScreenUtil.getInstance().getScreenWidth();
    }

    /**
     * 弹窗的高度，用来动态设定当前弹窗的高度，受getMaxHeight()限制
     *
     * @return
     */
    protected int getPopupHeight() {
        return 0;
    }

    public void setEventBus(EventBus eventBus) {
        this.eventBus = eventBus;
    }


    @Override
    public void onOptClick(View view, Object object) {
        switch (view.getId()){
            case R.id.tv:
                break;
            default:break;
        }
    }

    public void setPersonnelListList(List<PersonnelList> personnelListList) {
        this.personnelListList = personnelListList;
        if(personnelListSelectAdapter!=null){
            personnelListSelectAdapter.setDataSource(personnelListList);
        }
    }
}